package gmail_test;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;


public class Screenshoting {

	public static String Screenshot(WebDriver driver)
	{
		
		File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
		
		Calendar calendar = Calendar.getInstance();
		SimpleDateFormat formatDate = new SimpleDateFormat("ddMMyyyy_hh-mm-ss"); 
		String folderName = ".\\screenshots\\";
		String nameFile = "screenshot_"+formatDate.format(calendar.getTime())+".png";
		
		try 
		{
            FileUtils.copyFile(scrFile, new File(folderName+nameFile));

    		//Reporter.log("The end test <a href=."+(folderName+nameFile)+">screenshot</a>", true );
        } 
		catch (IOException e1) 
		{
            e1.printStackTrace();
        }
		
		return folderName+nameFile;
	}
}
